helloApp.service('LoginService', function ($http) {

    this.urlBase = "/api";

    this.login = function (user, callback) {

        $.ajax({
            url: this.urlBase+"/login",
            data: { j_username: user.username, j_password: user.password,
                j_spring_security_remember_me: user.rememberme, submit: "Login" },
            type: "POST",
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            ignoreAuthModule: 'ignoreAuthModule',
            success: function(result) {

                 callback(result);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                console.log("error login");
            }
        });
    };

    this.logout = function(callback) {

        $.ajax({
            url: this.urlBase+"/logout",
            type: "GET",
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            ignoreAuthModule: 'ignoreAuthModule',
            success: function(result) {

                callback();
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
            }
        });
    };
});

